#pragma once

class DeleteGroupHandler : public JsonRequest<DeleteGroupHandler> 
{
public:
	bool response()
	{
		std::string		gid;
		sql_string<>	sql;

		if(false == request::get("gid", gid))
		{
			err << "not find 'gid'";
			return false;
		}
	
		// 删除用户
		sql.format("delete from t_users where gid=%d",
				atoi(gid.c_str()));
		sql::execute(sql.c_str());
		// 删除组名
		sql.format("delete from t_users_group where gid=%d",
				atoi(gid.c_str()));
		if(1 != sql::execute(sql.c_str()))
		{
			err << "delete group failed:"
				<< mysql_error(g_mysql);
			return false;
		}
		
		json.push_back(JSONNode("errno", 0));
		return true;
	}
};
